package _base0to1;

/**
 * 1041. 困于环中的机器人
 */
public class No1041 {
    public boolean isRobotBounded(String instructions) {
        instructions += instructions;
        instructions += instructions;
        int x = 0, y = 0, direction = 100;
        for (char c : instructions.toCharArray()) {
            if (c == 'G') {
                switch (direction % 4) {
                    case 0:
                        y++;
                        break;
                    case 1:
                        x++;
                        break;
                    case 2:
                        y--;
                        break;
                    case 3:
                        x--;
                        break;
                }
            } else if (c == 'L') {
                direction--;
            } else
                direction++;
        }
        return x == 0 && y == 0;
    }
}
